home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / C⁄C++ / Xconq 7.0d37 / source / misc / map2g < prev    next >
Encoding:
Text File  |  1994-05-01  |  2.0 KB  |  83 lines  |  [TEXT/R*ch]

  1. #!/usr/local/bin/perl
  2. eval 'exec /usr/local/bin/perl -S $0 ${1+"$@"}'
  3.     if $running_under_some_shell;
  4.  
  5. require "getopts.pl";
  6. &Getopts('o:b:');
  7. die "Usage: map2g [-o outfile] [-b base-module] [infile]\n" if @ARGV > 1;
  8.  
  9. #
  10. # Get stdout set up and the default module name
  11. #
  12. if ( $opt_o ) {
  13.     #
  14.     # If they give us an output file name, open it
  15.     # and use it as the module name (minus path and extension).
  16.     #
  17.     open(STDOUT, ">$opt_o") || die "Couldn't open $opt_o for output: $!\n";
  18.     ($m = $opt_o) =~ s#(.*/)?(.*)\.g$#$2#;
  19. } elsif (@ARGV) {
  20.     #
  21.     # If they give us an input file,
  22.     # use it as the output file name (minus path and extension plus .g)
  23.     # and use it as the module name (minus path and extension).
  24.     #
  25.     ($m = $ARGV[0]) =~ s#(.*/)?(.*)\.map$#$2#;
  26.     unless ( -e "$m.g" ) {
  27.     open(STDOUT, ">$m.g") || die "Couldn't open $m.g for output: $!\n";
  28.     }
  29. } else {
  30.     #
  31.     # OK, we got nothin', output is stdout and module name is junk.
  32.     #
  33.     $m = 'xxx';
  34. }
  35.  
  36. #
  37. # This is the base-module option
  38. #
  39. if ( $opt_b ) {
  40.  
  41.     # Try to open it as a file
  42.     if ( open(BM, "$opt_b") ) {
  43.  
  44.     # assume that it's an old-style map, period or scenario file.
  45.     @types = grep(s/^\s*"(.)"\s+.*\s+ttype\s*(;.*)*$/$1/, <BM>);
  46.     $c = join('', @types);
  47.     }
  48.  
  49.     # strip the path and extension (if there is one).
  50.     $opt_b =~ s#(.*/)?(.*)\.(map|per|scn)$#$2#;
  51.  
  52.     # otherwise it's probably just a name.
  53.     $b = qq/  (default-base-module "$opt_b")\n/;
  54. }
  55.  
  56. while (<>) {
  57.  
  58.     # Nab the header line...
  59.     if (/^Xconq . [\+-]* \s*(.*)$/) {
  60.         print qq/(game-module "$m"\n$b  (blurb "$1")\n  )\n/;
  61.     next;
  62.     }
  63.  
  64.     # Get the world size...
  65.     if (/^Map ([0-9]*) ([0-9]*) /) {
  66.     local($i);
  67.  
  68.     # if this is .map file the the world is cylindrical.
  69.     print qq/(area $1 $2) (world $1)\n  (area (terrain (by-char "$c")\n/;
  70.     for ($i = 0; $i < $2; ++$i) {
  71.         $_ = <>;
  72.         chop;
  73.         print qq/  "$_"\n/;
  74.     }
  75.     # close the parens at the end of the map.
  76.     print "  ))\n";
  77.     next;
  78.     }
  79.  
  80.     s/^/;/;
  81.     print;
  82. }
  83.